{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "11bff9ad",
   "metadata": {},
   "source": [
    "——————\n",
    "* 时间：2022/10/17 week9\n",
    "* 记录人：小紫\n",
    "\n",
    "——————"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bcf2bd47",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "\n",
    "> 1. 用户输入\n",
    "\n",
    "> 2. 文本的格式化输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3019c7d2",
   "metadata": {},
   "source": [
    "## 1.用户输入\n",
    "* input方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "becd42f8",
   "metadata": {},
   "source": [
    "> 用户登录系统(usename和password是变量)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "dbcd3b54",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号：admin\n",
      "密码：123456\n"
     ]
    }
   ],
   "source": [
    "usename = input(\"账号：\")\n",
    "password = input(\"密码：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0e29f735",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "admin\n",
      "123456\n"
     ]
    }
   ],
   "source": [
    "print(usename)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c6f477f4",
   "metadata": {},
   "source": [
    "> 增加判断"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "0eb561b8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号：admin\n",
      "密码：123456\n",
      "登录成功~欢迎admin\n"
     ]
    }
   ],
   "source": [
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "usename = input(\"账号：\")\n",
    "password = input(\"密码：\")\n",
    "if user01 == usename and password01 == password:\n",
    "    print(\"登录成功~欢迎\"+user01)\n",
    "else:\n",
    "    print(\"账号不存在或密码不正确！请重新输入！\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1d8d15c1",
   "metadata": {},
   "source": [
    "> 循环！（使得输入密码错误之后还能有输入框，以及输入三次还不对后一小时后来尝试）\n",
    "\n",
    "> 中止循环 break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "707c049c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号：admin\n",
      "密码：123456\n",
      "账号不存在或密码不正确！请重新输入！您还有2次尝试的机会\n",
      "账号：admin\n",
      "密码：123456\n",
      "账号不存在或密码不正确！请重新输入！您还有1次尝试的机会\n",
      "账号：admin\n",
      "密码：123456\n",
      "账号不存在或密码不正确！请1小时后再来尝试\n"
     ]
    }
   ],
   "source": [
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "for i in range(3,0,-1):\n",
    "    username = input(\"账号：\")\n",
    "    password = input(\"密码：\")\n",
    "    if user01 == usename and password01 == password:\n",
    "        print(\"登录成功~欢迎\"+user01)\n",
    "        break\n",
    "    else:\n",
    "        if i>1:\n",
    "            print(\"账号不存在或密码不正确！请重新输入！您还有\" +str(i-1)+ \"尝试的机会\")\n",
    "        else:\n",
    "            print(\"账号不存在或密码不正确！请1小时后再来尝试\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ebcc0cf",
   "metadata": {},
   "source": [
    "## 2.字符串的格式化输出\n",
    "\n",
    "> 1. 字符串的拼接\n",
    "> 2. 占位符\n",
    "> 3. 格式化输出的方法：format()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "54b51cbb",
   "metadata": {},
   "source": [
    "* 用户的信息输入（完善信息）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "f5478f99",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：hh\n",
      "地区：yh\n",
      "工作：kk\n",
      "年龄：ll\n",
      "期待薪资：ll\n"
     ]
    }
   ],
   "source": [
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info = '''---------INFO ''' + name + ''' --------\n",
    "地区：''' + region + '''\n",
    "工作：''' + job + '''\n",
    "年龄：''' + age + '''\n",
    "期待薪资：''' + salary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "d78fc994",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "---------INFO hh--------\n",
      "地区：yh\n",
      "工作：kk\n",
      "年龄：ll\n",
      "期待薪资：ll\n"
     ]
    }
   ],
   "source": [
    "print(info)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b2550b8d",
   "metadata": {},
   "source": [
    "* 占位符  局限性：有序，个数确定，不能乱写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "37b9376c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：mm\n",
      "地区：jj\n",
      "工作：kk\n",
      "年龄：ll\n",
      "期待薪资：kk\n",
      "---------INFO mm --------\n",
      "地区：jj\n",
      "工作：kk\n",
      "年龄：ll\n",
      "期待薪资：kk \n"
     ]
    }
   ],
   "source": [
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info = '''---------INFO %s --------\n",
    "地区：%s\n",
    "工作：%s\n",
    "年龄：%s\n",
    "期待薪资：%s '''%(name,region,job,age,salary)\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d11d2bc",
   "metadata": {},
   "source": [
    "* format()  不考虑顺序，只考虑一一对应的关系（书写规范，字符串中的字段一一对应，不考虑其顺序）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "86e486c5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：kk\n",
      "地区：kk\n",
      "工作：ll\n",
      "年龄：ll\n",
      "期待薪资：oo\n",
      "---------INFO kk --------\n",
      "地区：kk\n",
      "工作：ll\n",
      "年龄：ll\n",
      "期待薪资：oo \n"
     ]
    }
   ],
   "source": [
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info = '''---------INFO {昵称} --------\n",
    "地区：{地区}\n",
    "工作：{工作职位}\n",
    "年龄：{年龄}\n",
    "期待薪资：{薪资} '''.format(工作职位=job,薪资=salary,昵称=name,年龄=age,地区=region)\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1509d9f3",
   "metadata": {},
   "source": [
    "## 课后作业： \n",
    "> 1. 第二章p93前所有项目练习（下周讲）\n",
    "> 2. 购物车项目\n",
    ">> 要求：\n",
    ">>  1. 运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    ">>  2. 让用户输入商品编号进行商品的购买。\n",
    ">>  3. 用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。\n",
    ">>  4. 用户可以随时退出购买，推出时打印用户已购买的商品和支付宝余额。\n",
    "\n",
    "* 网上很多人有写购物车项目可以参考（但是一般看不懂，非常炫酷）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9bd452d5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
